<template>
  <div>
    <el-container>
      <el-header>
        <h1>
          <div class="el-icon-s-unfold" @click="flag = !flag"></div>
          后台管理系统
                     <el-button type="primary" class="btn" @click="exit">退出登录</el-button>
          <div class="el-icon-menu quan" @click="quanping"></div>
        </h1>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu router :collapse="flag" class="el-menu-vertical-demo">
            <el-submenu index="/tushu">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>图书管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="/tushu">图书列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="/guoji">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>国际化</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="guoji">国际列表</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-menu-item-group>
              <el-menu-item index="/jichu">
                <i class="el-icon-menu"></i>
                <span slot="title">基础表格</span>
              </el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item index="/xuan">
                <i class="el-icon-menu"></i>
                <span slot="title">tab选项卡</span>
              </el-menu-item>
            </el-menu-item-group>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 面包屑导航 -->
          <div class="tab">
            <el-tag
              class="el-tab"
              v-for="(tag, index) in tags"
              :key="tag.name"
              closable
              @click="$router.push({ path: tag.path })"
              @close="closeTag(index)"
            >
              {{ tag.name }}
            </el-tag>
            <el-dropdown @command="close">
              <span class="el-dropdown-link">
                标签选项<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">关闭所有</el-dropdown-item>
                <el-dropdown-item command="b">关闭其他</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <router-view></router-view
        ></el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      flag: false,
      tags: [
        {
          path: "/jichu",
          name: "基础表格",
        },
        {
          path: "/xuan",
          name: "tab选项卡",
        },
      ],
    };
  },
  methods: {
    // 全屏
    quanping() {
      var el = document.documentElement;
      var rfs =
        el.requestFullScreen ||
        el.webkitRequestFullScreen ||
        el.mozRequestFullScreen ||
        el.msRequestFullscreen;
      if (typeof rfs != "undefined" && rfs) {
        rfs.call(el);
      }
      return;
    },
    // 面包屑导航
    closeTag(index) {
      this.tags.splice(index, 1);
    },
    close(val) {
      if (val == "a") {
        this.tags = [];
        this.$router.push({ path: "/home" });
      } else if (val == "b") {
        this.tags = this.tags.filter((item) => {
          if (item.path == this.$route.path) {
            return item;
          }
        });
      }
    },
    // 退出登录
        exit() {
      localStorage.removeItem("token");
      this.$router.push({ path: "/login" });
      this.$http(
        "http://ceshi5.dishait.cn/admin/logout",
        "post"
      ).then((res) => {});
    },
  },
};
</script>

<style scoped>
h1 {
  float: left;
  line-height: 10px;
  color: #fff;
}
.el-header,
.el-footer {
  background-color: #a1c4f1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  color: #333;
  text-align: center;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-tab {
  margin: 6px;
}
.tab {
  margin-left: -996px;
}
.quan{
  float: right;
  margin-right: -1260px;
}
.btn{
  float: right;
  margin-right: -1200px;
  margin-top: -8px;
}
</style>
